<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>系统角色列表</title>
<script type="text/javascript">
	function deleteRole(id){
		art.dialog({
			content:"确认要删除该用户吗？",
			ok:function(){
				$.ajax({
					url:"${ctx}/role/whetherCanDelete",
					type:"POST",
					dataType:"text",
					data:"id="+id,
					success:function(data){
						if(data != "true"){
							art.dialog({content:"该角色已经被使用，无法删除",ok:true});
						}else{
							$.ajax({
								url:"${ctx}/role/delete",
								type:"POST",
								dataType:"text",
								data:"id="+id,
								success:function(data){
									if(data == "true"){
										art.dialog({content:"删除成功！",
											ok:function(){
												window.location.href="${ctx}/role/list";
											}
										});
									}else{
										art.dialog("删除失败！");
									}
								}
							});
						}
					}
				});
			},
			cancel:true
		});
		
	}

	/**
	 * 启用/禁用
	 */
	var str = "";
	function doED(status,id){
		if(status == "1"){
			str = "启用";
		}else if(status == "0"){
			str = "禁用";
		}
		
		art.dialog({
			content:"确认要"+str+"该角色吗？",
			ok:function(){
				if(status == "0"){//如果要禁用则，需要验证
					$.ajax({
						url:"${ctx}/role/whetherCanDelete",
						type:"POST",
						dataType:"text",
						data:"id="+id,
						success:function(data){
							if(data != "true"){
								art.dialog({content:"该角色已经被使用，无法禁用",ok:true});
							}else{
								done(status,id);
							}
						}
					});
				}else{
					done(status,id);
				}
			},
			cancel:true
		});
		
	}
	
	function done(status,id){
		$.ajax({
			url:"${ctx}/role/doED",
			type:"POST",
			dataType:"text",
			data:"id="+id+"&status="+status,
			success:function(msg){
				if(msg == "true"){
					art.dialog({content:str+"成功！",
						ok:function(){
							window.location.href="${ctx}/role/list";
						}
					});
				}else{
					art.dialog(str+"失败！");
				}
			}
		});
	}
	
</script>
</head>
<body>
	<div class="breadcrumbs" id="breadcrumbs">
		<script type="text/javascript">
        try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
    </script>

		<ul class="breadcrumb">
			<li><i class="ace-icon fa fa-home home-icon"></i> <a
				href="${ctx }/home/home">首页</a></li>
			<li class="active">系统管理</li>
			<li class="active">角色管理</li>
		</ul>
		<!-- .breadcrumb -->
	</div>

	<div class="page-content">
		<div class="page-header">
			<h1>
				角色管理 <small> <i class="ace-icon fa fa-double-angle-right"></i> 角色列表
				</small>
				<div style="float: right;">
					<button type="button"
						class="btn btn-primary btn-sm project-searchbutton">
						<i class="ace-icon fa fa-search"></i>展开查询
					</button>
					<shiro:hasPermission name="role:add">
						<button type="button" class="btn btn-success btn-sm"
							onclick="javascript:window.location.href='${ctx}/role/addInit'">
							<i class="ace-icon fa fa-plus"></i>新增角色
						</button>
					</shiro:hasPermission>
				</div>
			</h1>
		</div>
		<!-- /.page-header -->

		<div class="row">
			<div class="col-xs-12 project-searchbox" style="display: none;">
				<div class="well col-xs-12">
					<form id="roleForm" class="form-horizontal"
						action="${ctx }/role/list" method="post">
						<input type="hidden" id="pageNo" name="pageNo"
							value="${page.pageNo }" />
						<div class="col-xs-12 col-md-6 col-lg-4">
							<div class="form-group">
								<label for="inputEmail3" class="col-sm-4 control-label"><strong>角色名称</strong></label>
								<div class="col-sm-8">
									<input type="text" id="roleName" name="roleName"
										value="${role.roleName }" class="form-control"
										placeholder="角色名称">
								</div>
							</div>
						</div>
						<div class="col-xs-12 col-md-6 col-lg-4">
							<div class="form-group">
								<label for="inputEmail3" class="col-sm-4 control-label"><strong>状态</strong></label>
								<div class="col-sm-8">
									<select:option type="status" id="status" name="status"
										styleClass="form-control" blank="true" showValue="false"
										value="${role.status }" />
								</div>
							</div>
						</div>
						<div class="col-xs-12 col-md-6 col-lg-4">
							<div class="col-sm-8 col-sm-offset-4 project-nopadding"
								style="text-align: right;">
								<button type="button" class="btn btn-primary btn-sm"
									onclick="doSubmit('roleForm')">
									<i class="ace-icon fa fa-search"></i> 查询
								</button>
								<button type="button" class="btn btn-default btn-sm"
									onclick="doFormReset('roleForm')">
									<i class="ace-icon fa fa-undo"></i>重置
								</button>
								<!-- <button type="button" class="btn btn-default btn-sm">返回</button> -->
							</div>
						</div>
					</form>
				</div>
			</div>
			<div class="col-xs-12">
				<div class="space-10"></div>
				<div class="table-responsive">
					<display:table class="project-default project-colorful"
						name="page.result" style="width:100%;border:0;" id="role">
						<display:column title="序号" style="width:5%">${role_rowNum }</display:column>
						<display:column title="角色名称" style="width:20%">
							<a class="blue" href="${ctx }/role/view?id=${role.id}">
							<c:out value="${role.roleName }" escapeXml="true"></c:out>
								 </a>
						</display:column>
						<display:column property="rmk" title="描述" style="width:30%" escapeXml="true"/>
						<display:column property="createUser" title="创建人"
							style="width:10%" />
						<display:column title="创建时间 " style="width:15%">
							<fmt:formatDate value="${role.createTime }"
								pattern="yyyy-MM-dd HH:mm:ss" />
						</display:column>
						<display:column title="状态" style="width:10%">
							<select:writeClass type="status" value="${role.status }" />
						</display:column>
						<display:column title="操作" style="width:15%">
							<%-- <a class="blue" href="${ctx }/role/view?id=${role.id}" title="查看">
            					<i class="ace-icon fa fa-file-text bigger-130"></i>
            				</a>
            				&nbsp; --%>
							<shiro:hasPermission name="role:update">
								<a class="green" href="${ctx }/role/updateInit?id=${role.id}"
									title="修改"> <i class="ace-icon fa fa-edit bigger-130"></i>
								</a>
							</shiro:hasPermission>
							<shiro:hasPermission name="role:delete">
	            			&nbsp;
            				<a class="grey" href="javascript:void(0);"
									onclick="deleteRole('${role.id}')" title="删除"> <i
									class="ace-icon fa fa-trash bigger-130"></i>
								</a>
							</shiro:hasPermission>
							<shiro:hasPermission name="role:edRole">
            				&nbsp;
            				<c:if test="${role.status == '1' }">
									<a class="red" href="javascript:void(0);"
										onclick="doED('0','${role.id}')" title="禁用"> <i
										class="ace-icon fa fa-lock bigger-130"></i>
									</a>
								</c:if>
								<c:if test="${role.status == '0' }">
									<a class="green" href="javascript:void(0);"
										onclick="doED('1','${role.id}')" title="启用"> <i
										class="ace-icon fa fa-unlock bigger-130"></i>
									</a>
								</c:if>
							</shiro:hasPermission>
						</display:column>

					</display:table>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-xs-12">
				<div class="space-10"></div>
				<div class="project-pagebox">
					<div>
						<p:writerPage pageNo="${page.pageNo }"
							pageSize="${page.pageSize }" totalCount="${page.totalCount }"
							formId="roleForm" />
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>